home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / PRGMANIA / BFED.10 / WIND.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  20.5 KB  |  927 lines

  1. /********************************************
  2.     file: wind.c
  3.     utility:
  4.     date: 1989
  5.     author: Jim Charlton
  6.     modifications:
  7.         17 aug 96: C. Moreau: suppressed file_str var. 
  8.     comments: 
  9. *********************************************/
  10.  
  11. /********************************************
  12.     includes
  13. *********************************************/
  14. #include <stddef.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. #ifdef __PUREC__ 
  20. #include <aes.h>
  21. #include <vdi.h>
  22. #include <compend.h>
  23. #else
  24. #include <aesbind.h>
  25. #include <vdibind.h>
  26. #endif
  27.  
  28. #include "e:\proging\c\libs\malib\alert.h"
  29.  
  30. #include "bufman.h"
  31. #include "files.h"
  32. #include "init.h"
  33. #include "events.h"
  34. #include "main.h"
  35. #include "menu.h"
  36. #include "onepage.h"
  37. #include "send.h"
  38. #include "slider.h"
  39. #include "wind.h"
  40.  
  41. #include "bfed_rsc.h"
  42.  
  43. /********************************************
  44.     defines
  45. *********************************************/
  46.  
  47. /********************************************
  48.     locals vars declarations & definitions
  49. *********************************************/
  50. static char pos_str[32];
  51.  
  52. /********************************************
  53.     globals vars declarations
  54. *********************************************/
  55. int    partial = FALSE;
  56. int    draw_flag = FALSE;
  57. int    slid_flag = FALSE;
  58. int    arro_flag = FALSE;
  59. int black_white = FALSE;
  60. int grow_shrink = FALSE;
  61. int    info_hexa = FALSE;
  62. windowptr firstwindow = NULL;
  63. windowptr thefrontwin = NULL;
  64.  
  65. /********************************************
  66.     locals functions declarations
  67. *********************************************/
  68. static void window_resize(const int *message, const windowptr thewin);
  69. static void window_fullsize(const windowptr thewin);
  70. static void do_update(const int *message, const windowptr thewin);
  71. static int rc_intersect (GRECT *p1, GRECT *p2);
  72. static void window_update(const windowptr window, GRECT *r1);
  73. static int window_count(void);
  74.  
  75. /********************************************
  76.     globals functions definitions
  77. *********************************************/
  78. /*
  79.     name: window_do
  80.     utility: determines the type of window event and then calls
  81.         the appropriate function to handle the event.
  82.     comment: 
  83.     parameters:
  84.     return: none
  85.     date: 1989
  86.     author: Jim Charlton
  87.     modifications:
  88.         1995: C. Moreau: 
  89. */
  90. void window_do(int *message)
  91. {
  92.     const int handle = message[3];
  93.     const windowptr thewin = findwindowptr(handle);
  94.  
  95.     graf_mouse(M_OFF, 0L);
  96.     wind_update(BEG_UPDATE);
  97.  
  98.     switch (message[0])
  99.     {
  100.         case WM_REDRAW:
  101.             draw_flag = 0;
  102.             do_update(message, thewin);
  103.             break;
  104.  
  105.         case WM_NEWTOP:
  106.         case WM_TOPPED:
  107.             window_put_top(thewin);
  108.             break;
  109.  
  110.         case WM_MOVED:
  111.         case WM_SIZED:
  112.             window_resize(message, thewin);
  113.             redraw_vslider(thewin);
  114.             break;
  115.  
  116.         case WM_FULLED:
  117.             window_fullsize(thewin);
  118.             redraw_vslider(thewin);
  119.             break;
  120.  
  121.         case WM_CLOSED:
  122.             window_dispose(thewin);
  123.             dispose_buf(thewin);
  124.             break;
  125.         
  126.         case WM_ARROWED:
  127.             arro_flag = 0;
  128.             
  129.         case WM_VSLID:
  130.             slid_flag = 0;
  131.             vhandler(message, thewin);
  132.             break;
  133.             
  134.         case WM_BOTTOM:
  135.             if (ver_aes >= 0x410)
  136.                 wind_set (handle, WF_BOTTOM); 
  137.             break;
  138.  
  139.         case WM_ALLICONIFY:
  140.             window_iconify_all();
  141.             break;
  142.             
  143.         case WM_ICONIFY:
  144.             window_iconify(thewin);
  145.             break;
  146.  
  147.         case WM_UNICONIFY:
  148.             window_uniconify(thewin);
  149.             break;
  150.     }
  151.  
  152.     wind_update(END_UPDATE);
  153.     graf_mouse(M_ON, 0L);
  154. }
  155.  
  156. /*
  157.     name: window_resize
  158.     utility: move and resize a window
  159.     comment: redraws the window at it's new postion and updates all
  160.         of the window's position records.
  161.     parameters: int message: contain new window sizes
  162.                 windowptr thewin: contain old window sizes 
  163.     return: none
  164.     date: 1989
  165.     author: Jim Charlton
  166.     modifications:
  167.         1995: C. Moreau: 
  168.         12 may 96: C.Moreau: Take off thewin->fullsize=FALSE
  169.         16 aug 96: C.Moreau: Added parameter to optimize
  170. */
  171. static void window_resize(const int *message, const windowptr thewin)
  172. {
  173. #if 0
  174.     int x = (message[4] & ~0x7);
  175.     int y = message[5];
  176.     int w = ((message[6] & ~0x7) + 4);
  177.     int h = message[7];
  178. #else
  179.     int x = message[4];
  180.     int y = message[5];
  181.     int w = message[6];
  182.     int h = message[7];
  183. #endif
  184.     const int handle = message[3];
  185.  
  186.         /* Make sure that the window doesn't become too small. */
  187.     if (w < 80)
  188.         w = 80;
  189.     if (h < 80)
  190.         h = 80;
  191.  
  192.         /* Or too big */
  193.     {
  194.         int w_ful, h_ful, dummy;
  195.         
  196.         wind_get(handle, WF_FULLXYWH, &dummy, &dummy, &w_ful, &h_ful);
  197.         if (w > w_ful)
  198.             w = w_ful;
  199.         if (h > h_ful)
  200.             h = h_ful;
  201.     }
  202.     
  203.     /*
  204.         Redraw the window at it's new size.
  205.         And set the Window record data.
  206.     */
  207.     wind_set(handle, WF_CURRXYWH, x, y, w, h);
  208.  
  209.     wind_get(handle, WF_WORKXYWH,                    \
  210.              &thewin->work.g_x, &thewin->work.g_y,    \
  211.              &thewin->work.g_w, &thewin->work.g_h);
  212.  
  213.     if (thewin->form)    /* move also the form */
  214.     {
  215.         thewin->form->ob_x = thewin->work.g_x;
  216.         thewin->form->ob_y = thewin->work.g_y;
  217.     }
  218. }
  219.  
  220. /*
  221.     name: window_fullsize
  222.     utility: draws the window at it's fully defined size.  If the window
  223.         is at it's full size then this routines restores the window to it's
  224.         previous size.
  225.     comment: 
  226.     parameters:
  227.     return: none
  228.     date: 1989
  229.     author: Jim Charlton
  230.     modifications:
  231.         12 may 96: C. Moreau: changed code to come back to old size
  232.             when unfulled. Also take off thewin->box. 
  233.         16 aug 96: C. Moreau: Changed parameter from handle to thewin
  234. */
  235. static void window_fullsize(const windowptr thewin)
  236. {
  237.     const int handle = thewin->handle;    /* window handle */
  238.     int x, y, w, h;    /* window sizes */
  239.     int dummy;
  240.  
  241.     wind_get(handle, WF_CURRXYWH, &x, &y, &dummy, &dummy);
  242.  
  243.     if (thewin->fullsize)
  244.     {
  245.             /*        Back to normal size    */
  246.         wind_get(handle, WF_PREVXYWH, &dummy, &dummy, &w, &h);
  247.         thewin->fullsize = FALSE;
  248.     }
  249.     else
  250.     {
  251.             /*        Draw window at full size;    */
  252.         wind_get(handle, WF_FULLXYWH, &dummy, &dummy, &w, &h);
  253.         thewin->fullsize = TRUE;
  254.     }
  255.                     
  256.     wind_set(handle, WF_CURRXYWH, x, y, w, h);
  257.                 
  258.     wind_calc(WC_WORK, thewin->kind, x, y, w, h,    \
  259.             &thewin->work.g_x, &thewin->work.g_y,    \
  260.             &thewin->work.g_w, &thewin->work.g_h);
  261. }
  262.  
  263. /*
  264.     name: do_update
  265.     utility: Update all of the rectangles affected
  266.         by the update event.
  267.     comment: 
  268.     parameters:
  269.     return: none
  270.     date: 1989
  271.     author: Jim Charlton
  272.     modifications:
  273.         12 may 96: C. Moreau: include update_window function. 
  274.         16 aug 96: C. Moreau: REplace handle by findwinhandle(handle)
  275.                                 Added thewin to optimize.
  276. */
  277. static void do_update(const int *message, const windowptr thewin)
  278. {
  279.     const int handle = message[3];
  280.     GRECT r1, therect;
  281.  
  282.     therect.g_x = message[4];
  283.     therect.g_y = message[5];
  284.     therect.g_w = message[6];
  285.     therect.g_h = message[7];
  286.  
  287.     wind_get(handle, WF_FIRSTXYWH, &r1.g_x, &r1.g_y, &r1.g_w, &r1.g_h);
  288.  
  289.     while (r1.g_w && r1.g_h)
  290.     {
  291.         if (rc_intersect(&therect, &r1))
  292.         {
  293.             window_update(thewin, &r1);
  294.         }
  295.         wind_get(handle, WF_NEXTXYWH, &r1.g_x, &r1.g_y,    \
  296.                      &r1.g_w, &r1.g_h);
  297.     }
  298.  
  299.     redraw_vslider(thewin);
  300. }
  301.  
  302. /*
  303.     name: rc_intersect
  304.     utility: calculate the intersection of 2 rectangles.
  305.     comment: 
  306.     parameters:
  307.     return: 
  308.     date: 1989
  309.     author: Jim Charlton
  310.     modifications:
  311.         1995: C. Moreau: 
  312. */
  313. static int rc_intersect (GRECT *p1, GRECT *p2)
  314. {   
  315.     const int tx = max(p2->g_x, p1->g_x);
  316.     const int ty = max(p2->g_y, p1->g_y);
  317.     const int tw = min(p2->g_x + p2->g_w, p1->g_x + p1->g_w);
  318.     const int th = min(p2->g_y + p2->g_h, p1->g_y + p1->g_h);
  319.  
  320.     p2->g_x = tx;
  321.     p2->g_y = ty;
  322.     p2->g_w = tw - tx;
  323.     p2->g_h = th - ty;
  324.     
  325.     return ((tw > tx) && (th > ty));
  326. }
  327.  
  328. /*
  329.     name: window_update
  330.     utility: execute the update procedure associated with the window.
  331.     comment: 
  332.     parameters:
  333.     return: none
  334.     date: 1989
  335.     author: Jim Charlton
  336.     modifications:
  337.         12 may 96: C. Moreau: added parameter to redraw only a rect.
  338. */
  339. static void window_update(const windowptr thewin, GRECT *rect)
  340. {
  341.     (*thewin->updateproc)(thewin, rect);
  342. }
  343.  
  344. /*
  345.     name: findwindowptr
  346.     utility: find the window record associated with the window
  347.         handle and return a pointer to that window record.
  348.     comment: 
  349.     parameters:
  350.     return: none
  351.     date: 1989
  352.     author: Jim Charlton
  353.     modifications:
  354.         1995: C. Moreau: 
  355. */
  356. windowptr findwindowptr(int handle)
  357. {
  358.     register windowptr thewin = firstwindow;
  359.  
  360.     for (thewin = firstwindow; thewin; thewin = thewin -> next)
  361.             /* tricky for-loop.  When thewin becomes a NULL the loop terminates  */
  362.         if (thewin->handle == handle)
  363.             break;
  364.  
  365.     if (!thewin)    /* if window not found */
  366.     {
  367.         if (handle != 0)
  368.         {
  369.             rsc_alert(NOWIND_2);
  370.             shutdown(2);
  371.         }
  372.         else
  373.             return NULL;
  374.     }
  375.  
  376.     return thewin;
  377. }
  378.  
  379. /*
  380.     name: window_new
  381.     utility: create & draw a new window.
  382.     comment:     
  383.                 1.)  create the window.
  384.                 2.)  draw the window with the wind_open()
  385.                 3.)  create and setup the window record.
  386.     parameters:
  387.     return: 
  388.     date: 1989
  389.     author: Jim Charlton
  390.     modifications:
  391.         12 may 96: C. Moreau: Extracted window insertion
  392.         in insertwindowptr.
  393. */
  394. windowptr window_new(int thekind)
  395. {
  396.     int            handle;    /* window handle */
  397.     windowptr    thewin = NULL;    /* window ptr */
  398.         /* max window width and height */
  399.     const int    wwind = min(wdesk, gl_wchar*WIDTH_WIN);
  400.      const int    hwind = hdesk;
  401.     
  402.         /* take off SMALLER button if AES < 4.10 */
  403.     if (ver_aes < 0x410 && (thekind & SMALLER))
  404.         thekind ^= SMALLER;
  405.     
  406.         /*    Create the information for the window.  
  407.             Max size is the desktop. */
  408. /***
  409.     do smthg for window to not override
  410. ***/
  411.  
  412.     handle = wind_create(thekind, xdesk, ydesk,    wwind, hwind);
  413.     if (handle < 0)
  414.     {
  415.         rsc_alert(NOWIND_3);
  416.     }
  417.     else
  418.     {
  419.             /*    Allocate space for window record. */
  420.         thewin = (windowptr) malloc(sizeof(windowrec));
  421.         if (!thewin)
  422.         {
  423.             wind_delete(handle); /* delete the window created above  */
  424.             rsc_alert(NOMEM_5);
  425.         }
  426.          else
  427.          {
  428.                 /* Initialize window data structure. */
  429.             thewin->next            = NULL;
  430.             thewin->handle            = handle;
  431.             thewin->kind            = thekind;
  432.             thewin->fullsize        = TRUE;
  433.             thewin->graf.handle     = open_vwork(&thewin->graf.mfdb);
  434.             thewin->updateproc    = (one_page);
  435.             thewin->headptr          = NULL;
  436.             thewin->startmark       = 1;
  437.             thewin->endmark          = 0;
  438.             thewin->markson         = 0;
  439.             thewin->xcur              = 0;
  440.             thewin->ycur              = 0;
  441.             thewin->topchar          = 0;
  442.             thewin->flen              = 0;
  443.             thewin->position          = 0;
  444.             thewin->vslidepos       = 0;
  445.             thewin->icount              = 0;
  446.             thewin->changed          = FALSE;    
  447.             thewin->prot              = TRUE;
  448.             thewin->form            = NULL;
  449.             thewin->icon            = FALSE;
  450.  
  451.             {
  452.                 char *string;
  453.         
  454.                 rsrc_gaddr(R_STRING, S_NOINFO, &string);
  455.                 strcpy(thewin->info, string);
  456.                 wind_set(handle, WF_INFO, thewin->info, 0, 0);
  457.                 rsrc_gaddr(R_STRING, S_UNTITLED, &string);
  458.                 strcpy(thewin->title, string);
  459.                 wind_set(handle, WF_NAME, thewin->title, 0, 0);
  460.             }
  461.             
  462.                  /* set text alignment to bottom left  for all windows   */
  463.             {
  464.                 int dummy;
  465.                 vst_alignment(thewin->graf.handle, 0, 3, &dummy, &dummy);
  466.             }
  467.                     
  468.             insertwindowptr(thewin);
  469.         }
  470.     }
  471.     
  472.     return thewin;
  473. }
  474.  
  475. /*
  476.     name: insertwindowptr
  477.     utility:     Insert into windowlist.
  478.     comment: 
  479.     parameters: windowptr: window struct  to add
  480.     return: none
  481.     date: 12 may 96
  482.     author: C. Moreau
  483.     modifications: This was extracted from wind_new function.
  484. */
  485. void insertwindowptr(windowptr thewin)
  486. {
  487.     register windowptr winptr = (windowptr)&firstwindow;  
  488.  
  489. /* firstwindow is a pointer to the first windowrec in the linked list and  */
  490. /* is initialized to NULL.  Since the first thing in a windowrec is       */
  491. /* 'next', the pointer to the next windowrec, then                          */
  492. /* '(windowptr)&firstwindow->next' or windptr->next starts at firstwindow */
  493. /* What a kludge to save a bit of code!  Below is some commented out      */
  494. /* tested code that is clearer.                                           */
  495. /*  if(!firstwindow)
  496.       firstwindow = *thewin;  
  497.     else                    
  498.     {   winptr = firstwindow;  
  499.          while(winptr -> next) 
  500.         winptr = winptr -> next;
  501.         winptr -> next = *thewin;
  502.     }
  503.     
  504. */        
  505.     while(winptr -> next)
  506.         winptr = winptr -> next;
  507.  
  508.     winptr->next = thewin;
  509. }
  510.  
  511. /*
  512.     name: window_open
  513.     utility: 
  514.     comment: 
  515.     parameters:
  516.     return: none
  517.     date: 1989
  518.     author: Jim Charlton
  519.     modifications:
  520.         aug 96: C. Moreau: added const handle to look better 
  521. */
  522. void window_open(windowptr thewin)
  523. {
  524.     const int handle = thewin->handle;    /* window handle */
  525.     int x_full, y_full, w_full, h_full;    /* window full sizes */
  526.  
  527.     wind_get(handle, WF_FULLXYWH, &x_full, &y_full, &w_full, &h_full);
  528.     
  529.         /*    A little flim-flammery. */
  530.     if (grow_shrink)
  531.         graf_growbox(0, 0, 0, 0, x_full, y_full, w_full, h_full);
  532.  
  533.         /*    Draw the window. */
  534.     wind_open(handle, x_full, y_full, w_full, h_full);
  535.         
  536.     wind_get(handle, WF_WORKXYWH,                            \
  537.                 &thewin->work.g_x, &thewin->work.g_y,    \
  538.                 &thewin->work.g_w, &thewin->work.g_h);
  539.     window_put_top(thewin);
  540.     window_info(thewin);
  541. }
  542.  
  543. /*
  544.     name: window_dispose
  545.     utility: Closes the window and disposes the storage for
  546.         the window record.
  547.     comment: 
  548.     parameters:
  549.     return: none
  550.     date: 1989
  551.     author: Jim Charlton
  552.     modifications:
  553.         1995: C. Moreau: added grow_shrink option
  554. */
  555. void window_dispose(windowptr thewin)
  556. {
  557.     wind_close(thewin->handle);
  558.  
  559.     if (grow_shrink)
  560.         graf_shrinkbox(0, 0, 0, 0,                             \
  561.                         thewin->work.g_x, thewin->work.g_y,    \
  562.                         thewin->work.g_w, thewin->work.g_h);
  563.     
  564.     window_resources_dispose(thewin);
  565. }
  566.  
  567. /*
  568.     name: window_resources_dispose
  569.     utility: 
  570.     comment: 
  571.     parameters:
  572.     return: none
  573.     date: 1989
  574.     author: Jim Charlton
  575.     modifications:
  576.         1995: C. Moreau: 
  577. */
  578. void window_resources_dispose(windowptr thewin)
  579. {
  580.     register windowptr winptr = (windowptr) &firstwindow;
  581.  
  582.         /*        Remove window record from window list. */
  583.     wind_delete(thewin->handle);
  584.  
  585.     while(winptr->next)
  586.     {
  587.         if (winptr->next == thewin)
  588.             break;
  589.         else
  590.             winptr = winptr->next;
  591.     }
  592.     
  593.     if (!winptr->next)
  594.     {
  595.         rsc_alert(NOWIND_4);
  596.         shutdown(2);
  597.     }
  598.     else
  599.     {
  600.         winptr->next = winptr->next->next;
  601.  
  602.             /*    Update the front window pointer. */
  603.         if (!firstwindow)
  604.             thefrontwin = NULL;
  605.         else
  606.         {
  607.             if (winptr == (windowptr) &firstwindow)
  608.                 window_put_top(winptr->next);
  609.             else
  610.                 window_put_top(winptr);
  611.         }
  612.     
  613.             /*        Close workstation associated with window. */
  614.         if (!thewin->form)
  615.             v_clsvwk(thewin->graf.handle);
  616.     
  617.             /*        Release window storage. */
  618.         free(thewin);
  619.     }
  620. }
  621.  
  622. /*
  623.     name: window_put_top
  624.     utility: Force a window to the front.
  625.     comment: 
  626.     parameters:
  627.     return: none
  628.     date: 1989
  629.     author: Jim Charlton
  630.     modifications:
  631.         10 may 96: C.Moreau: Added code to update info in menu 
  632. */
  633. void window_put_top(windowptr thewin)
  634. {
  635.     thefrontwin = thewin;
  636.     wind_set(thewin->handle, WF_TOP, 0, 0, 0, 0);
  637.     update_menu();
  638. }
  639.  
  640. /*
  641.     name: window_rot
  642.     utility: Rotate windows
  643.     comment: 
  644.     parameters:
  645.     return: none
  646.     date: 1989
  647.     author: Jim Charlton
  648.     modifications:
  649.         1995: C. Moreau: 
  650. */
  651. void window_rot(void)
  652. {
  653.     if (thefrontwin)
  654.     {
  655.         windowptr winptr;
  656.  
  657.         if (thefrontwin->next) 
  658.             winptr = thefrontwin->next;
  659.         else
  660.             winptr = firstwindow;
  661.         
  662.         window_put_top(winptr);
  663.     }
  664. }
  665.  
  666. /*
  667.     name: window_blank
  668.     utility: Fill in blank the window
  669.     comment: 
  670.     parameters:
  671.     return: none
  672.     date: 1989
  673.     author: Jim Charlton
  674.     modifications:
  675.         1995: C. Moreau: 
  676. */
  677. void window_blank(windowptr thewin)
  678. {
  679.     const int grafhandle = thewin->graf.handle;
  680.  
  681.     pxyarray[0] = thewin->work.g_x;
  682.     pxyarray[1] = thewin->work.g_y;
  683.     pxyarray[2] = thewin->work.g_x + thewin->work.g_w;
  684.     pxyarray[3] = thewin->work.g_y + thewin->work.g_h;
  685.     vsf_interior(grafhandle, FIS_SOLID);  /* set for solid fill */
  686.  
  687.     if (black_white)
  688.         vsf_color(grafhandle, 1);    /*  blank to black  */
  689.     else
  690.         vsf_color(grafhandle, 0);    /*  blank to white  */
  691.     
  692.     v_bar(grafhandle, pxyarray);        /* blank the interior */
  693. }
  694.  
  695. /*
  696.     name: window_info
  697.     utility: Update information in info bar
  698.     comment: 
  699.         Need to print in the info bar of the window, the actual position
  700.         of the cursor, the size of the file, the state of the file
  701.         (protected).
  702.         We use text in RSC. The string is made by a sprintf.
  703.     parameters:
  704.     return: none
  705.     date: 1995
  706.     author: C. Moreau
  707.     modifications:
  708. */
  709. void window_info(windowptr thewin)
  710. {    
  711.     char *prot_str, *notprot_str;
  712.     
  713.     rsrc_gaddr(R_STRING, S_PROTECTED, &prot_str);    
  714.     rsrc_gaddr(R_STRING, S_NOTPROTECTED, ¬prot_str);    
  715.  
  716.     sprintf(thewin->info, " %s %ld/%ld %s ",                \
  717.              pos_str, thewin->position, thewin->flen,        \
  718.              (thewin->prot?prot_str:notprot_str) );
  719.              
  720.     wind_set(thewin->handle, WF_INFO, &thewin->info);
  721. }
  722.  
  723. /*
  724.     name: window_title
  725.     utility: Update information in title bar
  726.     comment: 
  727.     parameters: pointer on window structure
  728.     return: none
  729.     date: 1995
  730.     author: C. Moreau
  731.     modifications:
  732. */
  733. void window_title(windowptr thewin)
  734. {
  735.     wind_set(thewin->handle, WF_NAME, &thewin->title);
  736. }
  737.  
  738. /*
  739.     name: window_count
  740.     utility: count the number of windows on the screen
  741.     comment: 
  742.     parameters: none
  743.     return: int
  744.     date: 14 august 96
  745.     author: C.Moreau
  746.     modifications:
  747. */
  748. static int window_count(void)
  749. {
  750.     int nb = 0;
  751.     windowptr thewindow = firstwindow;
  752.     
  753.     do
  754.     {
  755.         if (!thewindow->form)
  756.             nb++;
  757.         thewindow = thewindow->next;
  758.     } while (thewindow);
  759.     
  760.     return nb;
  761. }
  762.  
  763. /*
  764.     name: window_tile
  765.     utility: Tile windows horizontaly or verticaly
  766.     comment: 
  767.         This first count the number of windows to know the divide factor
  768.         to apply to the screen (variable nb_of_windows). (The size of a
  769.         window is size of the screen (wdesk or hdesk) divided by the
  770.         number of windows (nb_windows) ). We call count_windows to know
  771.         the number of work windows.
  772.         We resize and move all windows with the new parameters by using
  773.         do_resize function.
  774.         w_full and h_full are the maximum size of a window (thewindow).
  775.         The first window will be at 0,0 the second at his right, and so
  776.         on. window_nb * ( wdesk or hdesk / nb_of_windows )
  777.     parameters: int horiz_verti 
  778.                     0 tile horiz
  779.                     1 tile verti
  780.     return: none
  781.     date: 1995
  782.     author: C. Moreau
  783.     modifications:
  784. */
  785. void window_tile(int horiz_verti)
  786. {
  787.     int window_nb = 0;        /* window number in opens windows */
  788.     int dummy;
  789.     int w_full, h_full;        /* window full sizes */
  790.         /* number of open window */
  791.     int nb_of_windows = window_count();
  792.     int w_wind = (wdesk/nb_of_windows)-1,
  793.         h_wind = (hdesk/nb_of_windows)-1;    /* window sizes */
  794.     windowptr thewindow = firstwindow;    /* window ptr */
  795.         
  796.     do
  797.     {
  798.         if (!thewindow->form)
  799.         {
  800.             wind_get(thewindow->handle, WF_FULLXYWH,     \
  801.                     &dummy, &dummy, &w_full, &h_full);
  802.         
  803.             message[3] = thewindow->handle;
  804.             if (horiz_verti)        /* tile verti */
  805.             { 
  806.                 message[4] = 0;
  807.                 message[5] = window_nb * h_wind;
  808.                 message[6] = w_full;
  809.                 message[7] = h_wind;
  810.             }
  811.             else
  812.             { 
  813.                 message[4] = window_nb * w_wind;
  814.                 message[5] = 0;
  815.                 message[6] = w_wind;
  816.                 message[7] = h_full;
  817.             }
  818.             window_resize(message, thewindow);
  819.             
  820.             window_nb++;
  821.         }
  822.         thewindow = thewindow->next;
  823.     } while (thewindow);
  824. }
  825.  
  826. /*
  827.     name: window_init
  828.     utility: initialize vars of wind.c module
  829.     comment: 
  830.     parameters: none
  831.     return: none
  832.     date: 10 may 96
  833.     author: C.Moreau
  834.     modifications:
  835. */
  836. void window_init(void)
  837. {
  838.     rsrc_gaddr(R_STRING, S_POSSTR, &pos_str);    
  839. }
  840.  
  841. /*
  842.     name: find_workwind
  843.     utility: find the working window.
  844.     comment:
  845.         called from dialog.c.
  846.         This return to a dialog the windowptr of the working window
  847.         witch is under. Useful for search and go_pos dialog.
  848.     parameters: none
  849.     return: windowptr
  850.     date: 11 may 96
  851.     author: C.Moreau
  852.     modifications:
  853. */
  854. windowptr find_workwind(void)
  855. {
  856.     
  857.     return NULL;
  858. }
  859.  
  860. /*
  861.     name: window_iconify
  862.     utility: iconify a window
  863.     comment: 
  864.     parameters:
  865.         windowptr thewin: window to iconify.
  866.     return: none
  867.     date: 23 jan 97
  868.     author: C.Moreau
  869.     modifications:
  870. */
  871. void window_iconify(windowptr thewin)
  872. {
  873.     if ( !thewin->form && !thewin->icon && ver_aes >= 0x410)
  874.     {
  875.         wind_set (thewin->handle, WF_ICONIFY, message[4], message[5], message[6], message[7]);
  876.         thewin->icon = TRUE;
  877.     }
  878. }
  879.  
  880. /*
  881.     name: window_iconify_all
  882.     utility: iconify all windows
  883.     comment: 
  884.     parameters: none
  885.     return: none
  886.     date: 23 jan 97
  887.     author: C.Moreau
  888.     modifications:
  889. */
  890. void window_iconify_all(void)
  891. {
  892.     if (ver_aes >= 0x410)
  893.     {
  894.         windowptr thewindow = firstwindow;
  895.  
  896.         while (thewindow)
  897.         {
  898.             if (!thewindow->form && !thewindow->icon)
  899.                 window_iconify(thewindow);
  900.                 
  901.             thewindow = thewindow->next;
  902.         }
  903.     }
  904. }
  905.  
  906. /*
  907.     name: window_uniconify
  908.     utility: uniconify a window
  909.     comment: 
  910.     parameters:
  911.         windowptr thewin: window to iconify.
  912.     return: none
  913.     date: 23 jan 97
  914.     author: C.Moreau
  915.     modifications:
  916. */
  917. void window_uniconify(windowptr thewin)
  918. {
  919.     if ( !thewin->form && thewin->icon && ver_aes >= 0x410 )
  920.     {
  921.         wind_set (thewin->handle, WF_UNICONIFY, message[4], message[5], message[6], message[7]);
  922.         thewin->icon = FALSE;
  923.         send_redraw(thewin);
  924.     }
  925. }
  926.  
  927.